package com.proxy.autoclick.common.valueobject;

import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

import javax.inject.Inject;
import javax.inject.Named;

import com.proxy.autoclick.ui.layout.MainFrame;

@Named
public class ValidProxyQueue {
	
	private BlockingQueue<Proxy> blockingQueue = new LinkedBlockingQueue<Proxy>();
	
	@Inject
	private MainFrame mainFrame;
	
	public void put(Proxy proxy)
	{
		try 
		{
//			String message = String.format("Add a valid proxy: %s to Queue.", proxy.getProxy());
//			mainFrame.setTextAreaText(message);
			this.blockingQueue.put(proxy);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	
	public void put(List<Proxy> proxyList)
	{
		if(proxyList == null || proxyList.isEmpty())
			return;
		try 
		{
			for(Proxy proxy : proxyList)
			{
				this.blockingQueue.put(proxy);
			}
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	
	public Proxy take()
	{
		try {
			return this.blockingQueue.take();
		} catch (InterruptedException e) {
			e.printStackTrace();
			return null;
		}
	}

}
